package com.bcxj.apipassenger.Service;

import com.bcxj.apipassenger.remote.ServicePassengerUserClient;
import com.bcxj.internalcommon.dto.ResponseResult;
import com.bcxj.internalcommon.dto.TokenResult;
import com.bcxj.internalcommon.entity.PassengerUser;
import com.bcxj.internalcommon.util.JwtUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * ClassName: UserService
 * Package: com.bcxj.apipassenger.Service
 * Description:
 *
 * @Author BCXJ
 * @Create 2024/10/3 20:57
 * @Version 1.0
 * @Since 1.0
 */
@Service
@Slf4j
public class UserService {

    @Autowired
    private ServicePassengerUserClient servicePassengerUserClient;

    /**
     * 根据accessToken获取用户信息
     * @param accessToken token
     * @return
     */
    public ResponseResult getUserByAccessToken(String accessToken) {
        log.info("accessToken:{}", accessToken);

        TokenResult tokenResult = JwtUtils.checkToken(accessToken);

        if (tokenResult == null) {
            return ResponseResult.fail("token错误");
        }

        String phone = tokenResult.getPhone();
        PassengerUser passengerUser = new PassengerUser();

        ResponseResult userInfo = servicePassengerUserClient.getUserInfo(phone);

        return userInfo;
    }

}
